package day0719API;
//StringBuilder
public class Test5 {
    public static void main(String[] args) throws InterruptedException {
        String  s="a";
        long time1=System.currentTimeMillis();
        for(int i=0;i<=25;i++){
            s=s+s;
        }
        //底层会创建很多个字符数组
        long time2=System.currentTimeMillis();
        System.out.println(time2-time1);//1281

        /*StringBuilder builder=new StringBuilder("a");
        //System.currentTimeMillis(): 调用System类的currentTimeMillis()方法获取当前系统时间的毫秒值
        long time1=System.currentTimeMillis();
        for(int i=0;i<=25;i++){
            builder.append(builder);
        }
        long time2=System.currentTimeMillis();
        //底层只会操作同一个字符数组
        System.out.println(time2-time1);*/




        String str="好好学习java";
        StringBuilder builder2=new StringBuilder(str);
        //1. append: 追加(字符串连接)
        builder2.append(", 为了找个好工作");
        System.out.println(builder2);//自动调用toString,将StringBuilder对象转化为String
        System.out.println(builder2.toString());//将StringBuilder对象转化为String

        //2.替换文字replace(start, end, String str)
        builder2.replace(4,8,"英语");//替换builder2中字符串的第4个到第8个字符(不会替换第8个)
        System.out.println(builder2);
        builder2.replace(4,6,"java");//替换builder2中字符串的第4个到第8个字符(不会替换第8个)
        System.out.println(builder2);

        //3.delete(start, end)//不会删除end位置的字符
        builder2.delete(0,9);
        System.out.println(builder2);

        //4.insert(index, "str"):　在index位置插入字符串ｓｔｒ
        builder2.insert(0,"学习,");
        System.out.println(builder2);

        //5.前后颠倒顺序
        builder2.reverse();
        System.out.println(builder2);
    }




}
